﻿#include "lvgl_bilibili_anim.h"
#include "lvgl_Project.h"
//#include "lvgl_SheZhi.h"



void lvgl_bilibili_anim_ready_zuo_image_cb_Jin(lv_anim_t * anim)
{
	lv_anim_del(&lvgl_bilibili_data.lv_anim_zuo_image_jin, NULL);

	lvgl_bilibili_anim_zuo_image_shangxia(lv_obj_get_y(lvgl_bilibili_data.lvgl_zuo_image), lv_obj_get_height(lv_scr_act())-120);
	lv_obj_invalidate(lvgl_bilibili_data.cont_main);
}

void lvgl_bilibili_anim_zuo_image_cb_Jin(void * arc, lv_anim_value_t v)
{
	lv_obj_set_x(arc, v);

	lv_obj_invalidate(lvgl_bilibili_data.cont_main);
}

//左测图片进入动效
void lvgl_bilibili_anim_zuo_image_jin(void)
{


	lv_anim_init(&lvgl_bilibili_data.lv_anim_zuo_image_jin);
	lv_anim_set_ready_cb(&lvgl_bilibili_data.lv_anim_zuo_image_jin, lvgl_bilibili_anim_ready_zuo_image_cb_Jin);
	lv_anim_set_exec_cb(&lvgl_bilibili_data.lv_anim_zuo_image_jin, lvgl_bilibili_anim_zuo_image_cb_Jin);
	lv_anim_set_values(
		&lvgl_bilibili_data.lv_anim_zuo_image_jin,
		lv_obj_get_x(lvgl_bilibili_data.lvgl_zuo_image),
		0

	);
	lv_anim_set_time(&lvgl_bilibili_data.lv_anim_zuo_image_jin, 300);
	lv_anim_set_var(&lvgl_bilibili_data.lv_anim_zuo_image_jin, lvgl_bilibili_data.lvgl_zuo_image);

	//lv_anim_set_playback_delay(&lvgl_bilibili_data.lv_anim_zuo_image_jin,1000);

	lv_anim_path_t path;
	lv_anim_path_init(&path);
	lv_anim_path_set_cb(&path, lv_anim_path_ease_out);
	//lv_anim_path_linear线性动画
	//lv_anim_path_step最后一步更改
	//lv_anim_path_ease_in开头很慢
	//lv_anim_path_ease_out最后慢
	//lv_anim_path_ease_in_out在开始和结束时也很慢
	//lv_anim_path_overshoot超出最终值
	//lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）

	//lv_anim_path_set_user_data(&path, &foo); /*Optional for custom functions*/

	lv_anim_set_path(&lvgl_bilibili_data.lv_anim_zuo_image_jin, &path);

	lv_anim_start(&lvgl_bilibili_data.lv_anim_zuo_image_jin);
}


void lvgl_bilibili_anim_ready_you_image_cb_Jin(lv_anim_t * anim)
{
	lv_anim_del(&lvgl_bilibili_data.lv_anim_you_image_jin, NULL);
	lvgl_bilibili_anim_you_image_shangxia(lv_obj_get_y(lvgl_bilibili_data.lvgl_you_image),lv_obj_get_height(lv_scr_act())-120);
}

void lvgl_bilibili_anim_you_image_cb_Jin(void * arc, lv_anim_value_t v)
{
	lv_obj_set_x(arc, v);

	lv_obj_invalidate(lvgl_bilibili_data.cont_main);
}

//右测图片进入动效
void lvgl_bilibili_anim_you_image_jin(void)
{


	lv_anim_init(&lvgl_bilibili_data.lv_anim_you_image_jin);
	lv_anim_set_ready_cb(&lvgl_bilibili_data.lv_anim_you_image_jin, lvgl_bilibili_anim_ready_you_image_cb_Jin);
	lv_anim_set_exec_cb(&lvgl_bilibili_data.lv_anim_you_image_jin, lvgl_bilibili_anim_you_image_cb_Jin);
	lv_anim_set_values(&lvgl_bilibili_data.lv_anim_you_image_jin,lv_obj_get_x(lvgl_bilibili_data.lvgl_you_image),236);

	lv_anim_set_time(&lvgl_bilibili_data.lv_anim_you_image_jin, 300);
	lv_anim_set_var(&lvgl_bilibili_data.lv_anim_you_image_jin, lvgl_bilibili_data.lvgl_you_image);

	//lv_anim_set_playback_delay(&lvgl_bilibili_data.lv_anim_you_image_jin,1000);

	lv_anim_path_t path;
	lv_anim_path_init(&path);
	lv_anim_path_set_cb(&path, lv_anim_path_ease_out);
	//lv_anim_path_linear线性动画
	//lv_anim_path_step最后一步更改
	//lv_anim_path_ease_in开头很慢
	//lv_anim_path_ease_out最后慢
	//lv_anim_path_ease_in_out在开始和结束时也很慢
	//lv_anim_path_overshoot超出最终值
	//lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）

	//lv_anim_path_set_user_data(&path, &foo); /*Optional for custom functions*/

	lv_anim_set_path(&lvgl_bilibili_data.lv_anim_you_image_jin, &path);

	lv_anim_start(&lvgl_bilibili_data.lv_anim_you_image_jin);
}



//进入窗口的动效
void lvgl_bilibili_anim_Jin(void)
{

	lvgl_bilibili_anim_zuo_image_jin();
	lvgl_bilibili_anim_you_image_jin();
	lvgl_bilibili_anim_yezi_image(lv_obj_get_x(lvgl_bilibili_data.lvgl_yezi_image), 160);

}


void lvgl_bilibili_anim_ready_zuo_image_cb_shang(lv_anim_t * anim)
{
	lv_anim_del(&lvgl_bilibili_data.lv_anim_zuo_image_shangxia, NULL);

	if (lv_obj_get_y(lvgl_bilibili_data.lvgl_zuo_image) == lv_obj_get_height(lv_scr_act())-100)
	{
		lvgl_bilibili_anim_zuo_image_shangxia(lv_obj_get_y(lvgl_bilibili_data.lvgl_zuo_image), lv_obj_get_height(lv_scr_act())-120);
	}
	else if (lv_obj_get_y(lvgl_bilibili_data.lvgl_zuo_image) == lv_obj_get_height(lv_scr_act())-120)
	{
		lvgl_bilibili_anim_zuo_image_shangxia(lv_obj_get_y(lvgl_bilibili_data.lvgl_zuo_image), lv_obj_get_height(lv_scr_act())-100);
	}
}

void lvgl_bilibili_anim_zuo_image_cb_shang(void * arc, lv_anim_value_t v)
{
	lv_obj_set_y(arc, v);

	lv_obj_invalidate(lvgl_bilibili_data.cont_main);
}

//右测图片上下动效
void lvgl_bilibili_anim_zuo_image_shangxia(int dat1, int dat2)
{

	lv_anim_init(&lvgl_bilibili_data.lv_anim_zuo_image_shangxia);
	lv_anim_set_ready_cb(&lvgl_bilibili_data.lv_anim_zuo_image_shangxia, lvgl_bilibili_anim_ready_zuo_image_cb_shang);
	lv_anim_set_exec_cb(&lvgl_bilibili_data.lv_anim_zuo_image_shangxia, lvgl_bilibili_anim_zuo_image_cb_shang);
	lv_anim_set_values(
		&lvgl_bilibili_data.lv_anim_zuo_image_shangxia,
		dat1,
		dat2
	);

	lv_anim_set_time(&lvgl_bilibili_data.lv_anim_zuo_image_shangxia, 1000);
	lv_anim_set_var(&lvgl_bilibili_data.lv_anim_zuo_image_shangxia, lvgl_bilibili_data.lvgl_zuo_image);

	//lv_anim_set_playback_delay(&lvgl_bilibili_data.lv_anim_zuo_image_shangxia,1000);

	lv_anim_path_t path;
	lv_anim_path_init(&path);
	lv_anim_path_set_cb(&path, lv_anim_path_linear);
	//lv_anim_path_linear线性动画
	//lv_anim_path_step最后一步更改
	//lv_anim_path_ease_in开头很慢
	//lv_anim_path_ease_out最后慢
	//lv_anim_path_ease_in_out在开始和结束时也很慢
	//lv_anim_path_overshoot超出最终值
	//lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）

	//lv_anim_path_set_user_data(&path, &foo); /*Optional for custom functions*/

	lv_anim_set_path(&lvgl_bilibili_data.lv_anim_zuo_image_shangxia, &path);

	lv_anim_start(&lvgl_bilibili_data.lv_anim_zuo_image_shangxia);
}


void lvgl_bilibili_anim_ready_you_image_cb_shang(lv_anim_t * anim)
{
	lv_anim_del(&lvgl_bilibili_data.lv_anim_you_image_shangxia, NULL);

	if (lv_obj_get_y(lvgl_bilibili_data.lvgl_you_image) == lv_obj_get_height(lv_scr_act())-100)
	{
		lvgl_bilibili_anim_you_image_shangxia(lv_obj_get_y(lvgl_bilibili_data.lvgl_you_image), lv_obj_get_height(lv_scr_act())-120);
	}else if (lv_obj_get_y(lvgl_bilibili_data.lvgl_you_image) == lv_obj_get_height(lv_scr_act())-120)
	{
		lvgl_bilibili_anim_you_image_shangxia(lv_obj_get_y(lvgl_bilibili_data.lvgl_you_image), lv_obj_get_height(lv_scr_act())-100);
	}
}

void lvgl_bilibili_anim_you_image_cb_shang(void * arc, lv_anim_value_t v)
{
	lv_obj_set_y(arc, v);

	lv_obj_invalidate(lvgl_bilibili_data.cont_main);
}

//右测图片上下动效
void lvgl_bilibili_anim_you_image_shangxia(int dat1,int dat2)
{

	lv_anim_init(&lvgl_bilibili_data.lv_anim_you_image_shangxia);
	lv_anim_set_ready_cb(&lvgl_bilibili_data.lv_anim_you_image_shangxia, lvgl_bilibili_anim_ready_you_image_cb_shang);
	lv_anim_set_exec_cb(&lvgl_bilibili_data.lv_anim_you_image_shangxia, lvgl_bilibili_anim_you_image_cb_shang);
	lv_anim_set_values(
		&lvgl_bilibili_data.lv_anim_you_image_shangxia,
		dat1,
		dat2
	);

	lv_anim_set_time(&lvgl_bilibili_data.lv_anim_you_image_shangxia, 1500);
	lv_anim_set_var(&lvgl_bilibili_data.lv_anim_you_image_shangxia, lvgl_bilibili_data.lvgl_you_image);

	//lv_anim_set_playback_delay(&lvgl_bilibili_data.lv_anim_you_image_shangxia,1000);

	lv_anim_path_t path;
	lv_anim_path_init(&path);
	lv_anim_path_set_cb(&path, lv_anim_path_linear);
	//lv_anim_path_linear线性动画
	//lv_anim_path_step最后一步更改
	//lv_anim_path_ease_in开头很慢
	//lv_anim_path_ease_out最后慢
	//lv_anim_path_ease_in_out在开始和结束时也很慢
	//lv_anim_path_overshoot超出最终值
	//lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）

	//lv_anim_path_set_user_data(&path, &foo); /*Optional for custom functions*/

	lv_anim_set_path(&lvgl_bilibili_data.lv_anim_you_image_shangxia, &path);

	lv_anim_start(&lvgl_bilibili_data.lv_anim_you_image_shangxia);
}







//叶子图片左右动效
void lvgl_bilibili_anim_ready_yezi_image_cb(lv_anim_t * anim)
{
	lv_anim_del(&lvgl_bilibili_data.lv_anim_yezi_image, NULL);

	if (lv_obj_get_x(lvgl_bilibili_data.lvgl_yezi_image) == 160)
	{
		lvgl_bilibili_anim_yezi_image(lv_obj_get_x(lvgl_bilibili_data.lvgl_yezi_image), 200);
	}
	else if (lv_obj_get_x(lvgl_bilibili_data.lvgl_yezi_image) == 200)
	{
		lvgl_bilibili_anim_yezi_image(lv_obj_get_x(lvgl_bilibili_data.lvgl_yezi_image), 160);
	}
}

void lvgl_bilibili_anim_yezi_image_cb(void * arc, lv_anim_value_t v)
{
	lv_obj_set_x(arc, v);

	lv_obj_invalidate(lvgl_bilibili_data.cont_main);
}


void lvgl_bilibili_anim_yezi_image(int dat1, int dat2)
{

	lv_anim_init(&lvgl_bilibili_data.lv_anim_yezi_image);
	lv_anim_set_ready_cb(&lvgl_bilibili_data.lv_anim_yezi_image, lvgl_bilibili_anim_ready_yezi_image_cb);
	lv_anim_set_exec_cb(&lvgl_bilibili_data.lv_anim_yezi_image, lvgl_bilibili_anim_yezi_image_cb);
	lv_anim_set_values(
		&lvgl_bilibili_data.lv_anim_yezi_image,
		dat1,
		dat2
	);

	lv_anim_set_time(&lvgl_bilibili_data.lv_anim_yezi_image, 2000);
	lv_anim_set_var(&lvgl_bilibili_data.lv_anim_yezi_image, lvgl_bilibili_data.lvgl_yezi_image);

	//lv_anim_set_playback_delay(&lvgl_bilibili_data.lv_anim_yezi_image,1000);

	lv_anim_path_t path;
	lv_anim_path_init(&path);
	lv_anim_path_set_cb(&path, lv_anim_path_ease_in_out);
	//lv_anim_path_linear线性动画
	//lv_anim_path_step最后一步更改
	//lv_anim_path_ease_in开头很慢
	//lv_anim_path_ease_out最后慢
	//lv_anim_path_ease_in_out在开始和结束时也很慢
	//lv_anim_path_overshoot超出最终值
	//lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）

	//lv_anim_path_set_user_data(&path, &foo); /*Optional for custom functions*/

	lv_anim_set_path(&lvgl_bilibili_data.lv_anim_yezi_image, &path);

	lv_anim_start(&lvgl_bilibili_data.lv_anim_yezi_image);
}




void lvgl_bilibili_anim_in_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_y(arc, v);
}

void lvgl_bilibili_anim_in_ready_cb(lv_anim_t* anim)
{

    lvgl_bilibili_anim_debug("---------anim in ready---------");


    lv_obj_set_pos(lvgl_bilibili_data.cont_main, 0, 0);

    lvgl_group_add_obj(&lvgl_bilibili_data.cont_main);
    lvgl_group_focus_obj(&lvgl_bilibili_data.cont_main);
    lvgl_send_event(&lvgl_bilibili_data.cont_main, CZ_EVENT_ANIM_IN_READY,NULL);

}

void lvgl_bilibili_anim_in_start(int mode, int time)
{
#if LVGL_ANIM_SWITCH

    lvgl_bilibili_anim_debug("---------anim in start---------");

    lv_anim_path_init(&lvgl_bilibili_data.anim_path_in);
    lv_anim_path_set_cb(&lvgl_bilibili_data.anim_path_in, LVGL_ANIM_IN_PATH);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）

    lv_anim_init(&lvgl_bilibili_data.anim_in);
    lv_anim_set_exec_cb(&lvgl_bilibili_data.anim_in, lvgl_bilibili_anim_in_cb);
    lv_anim_set_ready_cb(&lvgl_bilibili_data.anim_in, lvgl_bilibili_anim_in_ready_cb);
    lv_anim_set_values(&lvgl_bilibili_data.anim_in, lv_obj_get_y(lvgl_bilibili_data.cont_main),0);
    lv_anim_set_time(&lvgl_bilibili_data.anim_in, LVGL_ANIM_IN_TIME);
    lv_anim_set_var(&lvgl_bilibili_data.anim_in, lvgl_bilibili_data.cont_main);

    lv_anim_set_path(&lvgl_bilibili_data.anim_in, &lvgl_bilibili_data.anim_path_in);
    lv_anim_start(&lvgl_bilibili_data.anim_in);

#else


    lvgl_bilibili_anim_in_ready_cb(NULL);

#endif

}


void lvgl_bilibili_anim_out_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_y(arc, v);
}
void lvgl_bilibili_anim_out_ready_cb(lv_anim_t* anim)
{

    lvgl_bilibili_anim_debug("---------anim out ready---------");
    lvgl_bilibili_close();

}

void lvgl_bilibili_anim_out_start(int mode, int time)
{

    lvgl_group_remove_obj(&lvgl_bilibili_data.cont_main);




#if LVGL_ANIM_SWITCH

    lvgl_bilibili_anim_debug("---------anim out start---------");

    lv_anim_path_init(&lvgl_bilibili_data.anim_path_out);
    lv_anim_path_set_cb(&lvgl_bilibili_data.anim_path_out, LVGL_ANIM_OUT_PATH);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）

    lv_anim_init(&lvgl_bilibili_data.anim_out);

    lv_anim_set_exec_cb(&lvgl_bilibili_data.anim_out, lvgl_bilibili_anim_out_cb);
    lv_anim_set_ready_cb(&lvgl_bilibili_data.anim_out, lvgl_bilibili_anim_out_ready_cb);
    lv_anim_set_values(&lvgl_bilibili_data.anim_out, lv_obj_get_y(lvgl_bilibili_data.cont_main), lv_obj_get_height(lv_scr_act()));
    lv_anim_set_time(&lvgl_bilibili_data.anim_out, LVGL_ANIM_OUT_TIME);
    lv_anim_set_var(&lvgl_bilibili_data.anim_out, lvgl_bilibili_data.cont_main);

    lv_anim_set_path(&lvgl_bilibili_data.anim_out, &lvgl_bilibili_data.anim_path_out);
    lv_anim_start(&lvgl_bilibili_data.anim_out);

#else


    lvgl_bilibili_anim_out_ready_cb(NULL);

#endif

}

